/**
 *
 */
package vn.smartware.co.framework.db.factory;

import java.io.Serializable;
import java.sql.SQLException;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;

/**
 * DbResources
 * 
 * @author thuctt
 */
public class DbResources implements Serializable {

	/**
	 * serialVersionUID
	 */
	private static final long serialVersionUID = -6185706095342811102L;
	private static DbResources dbResources = null;
	
	/**
	 * get instance
	 * @return DbResources
	 * @throws SQLException 
	 */
	public static DbResources getInstance () throws SQLException {
		if (null == dbResources){
			dbResources =new DbResources();
		}
		return dbResources;
	}

	/**
	 * Constructor
	 * @throws SQLException 
	 *
	 */
	public DbResources() throws SQLException {
		
		try {
			Context ctx = new InitialContext();
			datasource = (DataSource) ctx.lookup("java:comp/env/jdbc/hms");
			
		} catch (NamingException e) {
			throw new SQLException(e.getMessage());
		}
	}
	
	private DataSource datasource;

	/**
	 * @return the datasource
	 */
	public DataSource getDatasource() {
		return datasource;
	}

	/**
	 * @param datasource the datasource to set
	 */
	public void setDatasource(DataSource datasource) {
		this.datasource = datasource;
	}
}
